package cn.rhl.projectinit.exception;

import cn.rhl.projectinit.common.BaseResponse;
import cn.rhl.projectinit.common.ResponseCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author rhl
 * @date 2024/12/22
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {


    @ExceptionHandler(value = BusinessException.class)
    public BaseResponse<?> businessExceptionHandler(BusinessException e) {
        log.error("business:", e);
        return BaseResponse.fail(e.getCode(), e.getMessage());
    }


    @ExceptionHandler(value = RuntimeException.class)
    public BaseResponse<?> businessExceptionHandler(RuntimeException e) {
        log.error("runTime:", e);
        return BaseResponse.fail(ResponseCode.SYSTEM_ERROR, e.getMessage());
    }

}
